package insight.google.game.era.bo.policy.gamecard;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import insight.google.game.era.bo.GameActionLog;
import insight.google.game.era.bo.GameRoom;
import insight.google.game.era.bo.GameUser;
import insight.google.game.era.bo.card.GameCard;
import insight.google.game.era.bo.policy.AbstractPolicy;
import insight.google.game.era.client.proxy.PlayerClientProxy;
import insight.google.game.era.client.proxy.PlayerClientProxyImpl;
import insight.google.game.era.core.Util;
import insight.google.game.era.mgr.GameLogManager;

public class AttackHorsePolicy extends AbstractPolicy {

    /**
	 * 
	 */
	private PlayerClientProxy playerClientProxy;

	@Override
	public boolean execute(GameUser original, GameUser[] targets, Map params) {
		// TODO Auto-generated method stub

        //get js component id
        String jsComponentId = (String)params.get("jsComponenetId");

    	playerClientProxy = PlayerClientProxyImpl.getInstance();

		GameRoom room = Util.getRoom();
		GameCard card = room.getCardByCardName("attackhorse");

		if(original.checkSameTypeEquipment(card)){
//			playerClientProxy.replaceEquipmentCard(original.getScriptProxy(), jsComponentId, card);
			original.replaceEquipmentCard(card, jsComponentId);
		}
		else{
			original.addEquipmentCards(card);
			original.setAttackDistance(original.getAttackDistance() + card.getDistance());
		}
		GameLogManager gameLogManager = room.getGameLogManager();
        gameLogManager.addGameLog(new GameActionLog(original.getName() + " has played attack horse."));

		Collection<GameUser> attackUsers = room.getAttackableUsers(original);
		List<String> userList = new ArrayList<String>();
		for (GameUser user : attackUsers) {
			userList.add(user.getName());
		}
		original.setAttackUserList(userList);
		
//        playerClientProxy.registerAttackableUser(original.getScriptProxy(), jsComponentId, attackUsers);

//        playerClientProxy.setActive(original.getScriptProxy(), jsComponenetId, true);
        
		original.registerAttackableUser(jsComponentId);
		original.refreshEquipmentCard(jsComponentId);
        original.setClientActive(true, jsComponentId);

        return true;
	}

}
